<?php

/**
 * NOTICE OF LICENSE
 *
 * THIS SOURCE FILE IS PART OF EVEBIT'S PRIVATE PROJECT.
 * 
 * DO NOT USE THIS FILE IN OTHER PLACE.
 *
 * @package   App_Sample
 * @author    Cheng Wei <berlios.o@gmail.com>
 * @version   $$Id: GetSourceValue.php 130 2011-03-18 03:10:02Z cheng.wei $$
 * @copyright Copyright (c) 2008 Evebit Inc. China (http://www.evebit.com)
 */

/**
 * Get value of backend source
 * 
 * @package   App_Sample
 * @author    Cheng Wei <berlios.o@gmail.com>
 * @version   $$Id: GetSourceValue.php 130 2011-03-18 03:10:02Z cheng.wei $$
 */
class Evebit_View_Helper_GetSourceValue extends Zend_View_Helper_Abstract {
	
	protected $sources = array();
	
	/**
	 * Get value
	 * 
	 * @return string
	 */
	public function getSourceValue($value, $type) {
		if (!isset($this->sources[$type])) {
			$class = ucfirst($type);
			if (!class_exists($class)) {
				$class = 'Backend_Model_Config_Source_' . $class;
			}
			if (!class_exists($class)) {
				throw new Exception("Class '$class' not exists");
			}
			$this->sources[$type] = new $class();
		}
		
		return $this->sources[$type]->getValue($value);
	}

}